package com.guojizhuang.APIdemo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;

public class PhoneServiceImpl {
    public void readFromHdfs(String hdfsUri) throws IOException {
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(hdfsUri), conf);
        FSDataInputStream in = null;
        BufferedReader reader = null;
        try {
            in = fs.open(new Path(hdfsUri));
            reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); // 使用UTF-8编码

            String line;
            while ((line = reader.readLine()) != null) {
                String[] wordlist = line.toString().split("\\s+");
                //转换成Json文件
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }
}
